@using MatBlazor.Demo.Models
@implements IDisposable
@inject UserAppModel UserAppModel;

<title>@(GenerateTitle())</title>

@code
{


    string GenerateTitle()
    {
        var title = "MatBlazor - Material Design components for Blazor and Razor Components";
        if (string.IsNullOrEmpty(UserAppModel.Title))
        {
            return title;
        }
        else
        {
            return $"{UserAppModel.Title} - {title}";
        }
    }

    protected override void OnInitialized()
    {
        base.OnInitialized();
        this.UserAppModel.TitleChanged += TitleChanged;
    }


    void TitleChanged(object s, EventArgs e)
    {
        this.InvokeAsync(() => { this.StateHasChanged(); });
    }


    public void Dispose()
    {
        this.UserAppModel.TitleChanged -= TitleChanged;
    }

}